package com.menhai.personmanagement.services;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.menhai.personmanagement.entity.ReportHealthrecord;
import com.menhai.personmanagement.entity.vo.HealthCheckVo;
import com.menhai.personmanagement.entity.vo.HealthRecordVo;
import com.menhai.personmanagement.mapper.ReportHealthrecordMapper;
/**
 * <p>
 * 报卡管理表 服务类
 * </p>
 *
 * @author shikun
 * @since 2021-11-25
 */
 @Service
public class ReportHealthRecordService{

  
   @Autowired
   private ReportHealthrecordMapper reportHealthrecordMapper;

   
   /**
  	 * 新增健康记录
  	 * @param Doctor
  	 * @return Map<String, Object>
  	 */
  	@Transactional
  	public Map<String, Object> addReportHealthrecord(ReportHealthrecord reportHealthrecord) {
  		Map<String,Object> resultMap = new HashMap<String,Object>();
  		try{	
  			//新建健康记录
  			int iRet = reportHealthrecordMapper.insert(reportHealthrecord);
  			if(iRet == 0){  //没有插入成功的数据
  				resultMap.put("success", "0");
  				resultMap.put("message", "插入成功的条数为0，操作健康记录失败！");
  				return resultMap;
  			}else{
  				resultMap.put("success", "1");
  				resultMap.put("message", "操作健康记录成功！");
  				return resultMap;
  			}
  		}catch(Exception e){
  			resultMap.put("success", "0");
  			resultMap.put("message", "操作健康记录失败！异常：" +e.getMessage());
  			e.printStackTrace();
  			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  		}
  		return resultMap;
  	}

  	
  	/**
  	 * 查询健康体检信息列表
  	 * @param healthCheckVo
  	 * @return
  	 */
  	public IPage<HealthRecordVo> getHealthRecordInfoList(HealthRecordVo healthRecordVo){
        Page<HealthRecordVo> page = new Page<>(healthRecordVo.getPageIndex(),healthRecordVo.getPageSize());
        return reportHealthrecordMapper.getHealthRecordInfoList(page,healthRecordVo);
    }
  	
  	/**
  	 * 根据记录id查询信息
  	 * @param id
  	 * @return
  	 */
  	public ReportHealthrecord getOneById(String id){
  		return reportHealthrecordMapper.getOneById(id);
  	}
  	
  	/**
  	 * 编辑信息
  	 * @param reportHealthcheck
  	 * @return
  	 */
	@Transactional
	public Map<String, Object> updateHealthRecord(ReportHealthrecord reportHealthrecord) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		try{	
			int iRet = reportHealthrecordMapper.update(reportHealthrecord);
			if(iRet == 0){  
				resultMap.put("success", "0");
				resultMap.put("message", "编辑成功的条数为0，编辑失败！");
				return resultMap;
			}
			resultMap.put("success", "1");
			resultMap.put("message", "编辑成功！");
		}catch(Exception e){
			resultMap.put("success", "0");
			resultMap.put("message", "编辑失败！异常：" +e.getMessage());
			e.printStackTrace();
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
		}
		return resultMap;
	}
	
	/**
	 * 获取二层主页
	 * @param frontTwoFlag
	 * @return
	 */
	public List<Map<String,Object>> getFrontTwo(String frontTwoFlag){
		return reportHealthrecordMapper.getFrontTwo(frontTwoFlag);
	}
	
	/**
	 * 问题列表
	 * @return
	 */
	public List<Map<String,Object>> getMould(){
		return reportHealthrecordMapper.getMould();
	}
	
	
	/**
	 * 获取记录信息
	 * @param id
	 * @return
	 */
	public Map<String,String> getHealthRecord(String id){
		return reportHealthrecordMapper.getHealthRecord(id);
	}
	
	/**
	 * 左侧树
	 * @param hosnum
	 * @return
	 */
	public List<Map<String,Object>> getCunRenShu(String hosnum){
		return reportHealthrecordMapper.getCunRenShu(hosnum);
	}
	
}
